import dayjs from 'dayjs';

const columns_fund_manager_change = [
  {
    title: '基金经理',
    dataIndex: 'name',
    key: 'name',
    render:(text:string)=>(
      text?text:'-'
    ),
    // width: 72,
  },
  {
    title: '起始日期',
    dataIndex: 'startDate',
    key: 'startDate',
    render:(text:string)=>(
      text?dayjs(text).format("YYYY-MM-DD"):'-'
    ),
    // width: 72,
  },
  {
    title: '截止日期',
    dataIndex: 'endDate',
    key: 'endDate',
    render:(text:string)=>(
      text?dayjs(text).format("YYYY-MM-DD"):'在职'
    ),
    // width: 72,
  },
  {
    title: '经历天数',
    dataIndex: 'cutDate',
    key: 'cutDate',
    render:(text:string)=>(
      text?text+'天':'-'
    ),
    align:'right',
    // width: 72,
  },
  {
    title: '累计收益(%)',
    dataIndex: 'unitNVRestored',
    key: 'unitNVRestored',
    // width: 200,
    align:'right',
    render:(text:number)=>(
      text||text===0?Number(text).toFixed(2):'-'
    ),
    // width: 72,

  },
  {
    title: '年化收益(%)',
    dataIndex: 'yearNvRestored',
    key: 'yearNvRestored',
    // width: 160,
    align:'right',
    render:(text:number)=>(
      text||text===0?Number(text).toFixed(2):'-'
    ),
    // width: 72,

  },
  {
    title: '最大回撤(%)',
    dataIndex: 'maxRetreat',
    key: 'maxRetreat',
    // width: 100,
    align:'right',
    render:(text:number)=>(
      text||text===0?Number(text).toFixed(2):'-'
    ),
    // width: 72,

  }
]
const columns_credit_alert = [
  {
    title: '序号',
    dataIndex: '',
    key: '',
    render:(text:string,record:any,index:number)=>(
      index+1
    ),
    align:'center',
    width:24
  },
  {
    title: '债券代码',
    dataIndex: 'bondCode',
    key: 'bondCode',
    render:(text:string)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 70,
    className:"table_bondCode"
  },
  {
    title: '债券名称',
    dataIndex: 'scuAbbr',
    key: 'scuAbbr',
    render:(text:string)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 96,
    className:"table_scuAbbr"


  },
  {
    title: '券种',
    dataIndex: 'fourthBTypeName',
    key: 'fourthBTypeName',
    render:(text:string)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 82,
    className:"table_fourthBTypeName"

  },
  {
    title: '是否城投债',
    dataIndex: 'cityDebt',
    key: 'cityDebt',
    render:(text:number)=>(
      Number(text)?'是':'否'
    ),
    ellipsis:true,
    width: 50,
    className:"table_cityDebt"

  },
  {
    title: '是否永续债',
    dataIndex: 'perpetualDebt',
    key: 'perpetualDebt',
    // width: 160,
    render:(text:number)=>(
      Number(text)?'是':'否'
    ),
    ellipsis:true,
    width: 50,
    className:"table_perpetualDebt"


  },
  {
    title: '主体最新信用评级',
    dataIndex: 'companyCRDesc',
    key: 'companyCRDesc',
    // width: 100,
    render:(text:number)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 68,
    className:"table_companyCRDesc"


  },
  {
    title: '债项评级',
    dataIndex: 'bondCRDesc',
    key: 'bondCRDesc',
    // width: 100,
    render:(text:number)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 55,
    className:"table_bondCRDesc"

    

  }
]

const columns_table_one = [
  {
    title: '申购费率',
    dataIndex: 'divIntervalDes',
    key: 'divIntervalDes',
    render:(text:string)=>(
      text?text:'-'
    ),
    // width: 72,
  },
  {
    title: '费率',
    dataIndex: 'chargeRateDes',
    key: 'chargeRateDes',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'right'
    // width: 72,
  }
  
]
const columns_table_two = [
  {
    title: '申购状态',
    dataIndex: 'applyingType',
    key: 'applyingType',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'center',
    width: 70,
  },
  {
    title: '赎回状态',
    dataIndex: 'redeemType',
    key: 'redeemType',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'center',
    width: 70,

  },
  {
    title: '日累计申购限额',
    dataIndex: 'largeApplyingMax',
    key: 'largeApplyingMax',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'center',
    width: 80,

    // width: 72,
  }
  
]
const columns_table_three = [
  {
    title: '费率类型',
    dataIndex: 'name',
    key: 'name',
    render:(text:string)=>(
      text?text:'-'
    ),
    width: 70,
    align:'center'
    // width: 72,
  },
  {
    title: '费率',
    dataIndex: 'fee',
    key: 'fee',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'right',
    width: 70,
    // width: 72,
  },
  {
    title: '同类平均',
    dataIndex: 'avgFee',
    key: 'avgFee',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'right',
    width: 80,
    // width: 72,
  }
  
]
const columns_three_table = {
  1:columns_table_one,
  2:columns_table_two,
  3:columns_table_three
}

const columns_add_table = [
  {
    title: '',
    dataIndex: 'year',
    key: 'year',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'center',
    onCell: (record:any, index:number) => {
      // console.log('(index as number) %2',record)
      return ({
      rowSpan: record.rowSpan
    })},
    // width: 72,
  },
  {
    title: '分红次数',
    dataIndex: 'dividendTimesYTD',
    key: 'dividendTimesYTD',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'center',
    onCell: (record:any, index:number) => {
      // console.log('(index as number) %2',record)
      return ({
      rowSpan: record.rowSpan
    })},
    // width: 72,
  }
  ,
  {
    title: '单位年度分红',
    dataIndex: 'unitProfitYTD',
    key: 'unitProfitYTD',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'center',
    onCell: (record:any, index:number) => {
      // console.log('(index as number) %2',record)
      return ({
      rowSpan: record.rowSpan
    })},
    // width: 72,
  },
  {
    title: '分红基准日',
    dataIndex: 'profitDistDate',
    key: 'profitDistDate',
    render:(text:string)=>(
      text?dayjs(text).format('YYYY-MM-DD'):'-'
    ),
    align:'center'
    // width: 72,
  },
  {
    title: '基准日单位净值',
    dataIndex: 'unitNV',
    key: 'unitNV',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'right'
    // width: 72,
  },
  {
    title: '单位分红',
    dataIndex: 'dividendRatioBeforeTax',
    key: 'dividendRatioBeforeTax',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'right'
    // width: 72,
  },
  {
    title: '分红比例(%)',
    dataIndex: 'dividendRate',
    key: 'dividendRate',
    render:(text:string)=>(
      text?text:'-'
    ),
    align:'right'
    // width: 72,
  }
  
]
const columns_stock_consensus_alert = [
  {
    title: '序号',
    dataIndex: '',
    key: '',
    render:(text:string,record:any,index:number)=>(
      index+1
    ),
    align:'center',
    width:24
    // width: 50,
  },
  {
    title: '股票代码',
    dataIndex: 'secuCode',
    key: 'secuCode',
    render:(text:string)=>(
      text?text:'-'
    ),
    width:55,
    ellipsis:true

    // width: 72,
  },
  {
    title: '股票名称',
    dataIndex: 'secuAbbr',
    key: 'secuAbbr',
    render:(text:string)=>(
      text?text:'-'
    ),
    width:55,
    ellipsis:true
    // width: 72,
  },
  {
    title: '申万行业',
    dataIndex: 'firstIndustryName',
    key: 'firstIndustryName',
    render:(text:string)=>(
      text?text:'-'
      ),
    width:167,
    ellipsis:true
    // width: 72,
  },
  {
    title: '所属板块',
    dataIndex: 'plateName',
    key: 'plateName',
    render:(text:string)=>(
      text?text:'-'
    ),
    width:55,
    ellipsis:true
    // width: 72,

  },
  {
    title: '占基金资产净值比例（％）',
    dataIndex: 'ratioInNv',
    key: 'ratioInNv',
    // width: 160,
    render:(text:number)=>(
      text||text===0?text:'-'
    ),
    align:'right',
    width:146,
    ellipsis:true
    // width: 72,

  }
];

const columns_credit_price = [
  {
    title: '序号',
    dataIndex: '',
    key: '',
    render:(text:string,record:any,index:number)=>(
      index+1
    ),
    align:'center',
    width:24
  },
  {
    title: '债券代码',
    dataIndex: 'bondCode',
    key: 'bondCode',
    render:(text:string)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 68,
    className:"table_bondCode"
  },
  {
    title: '债券名称',
    dataIndex: 'secuAbbr',
    key: 'secuAbbr',
    render:(text:string)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 92,
    className:"table_scuAbbr"


  },
  {
    title: '偏离度',
    dataIndex: 'deviateRange',
    key: 'deviateRange',
    render:(text:number)=>(
      text||text===0?text:'-'
    ),
    align:'right',
    ellipsis:true,
    width: 37,
    className:"table_fourthBTypeName"

  },
  {
    title: '成交价(元)',
    dataIndex: 'closeNetPrice',
    key: 'closeNetPrice',
    render:(text:number)=>(
      text||text===0?text:'-'
    ),
    align:'right',
    ellipsis:true,
    width: 52,
    className:"table_cityDebt"

  },
  {
    title: '中债估值(元)',
    dataIndex: 'cbvValueCleanPrice',
    key: 'cbvValueCleanPrice',
    render:(text:number)=>(
      text||text===0?text:'-'
    ),
    align:'right',
    ellipsis:true,
    width: 64,
    className:"table_perpetualDebt"


  },
  {
    title: '中证估值(元)',
    dataIndex: 'csiValueCleanPrice',
    key: 'csiValueCleanPrice',
    render:(text:number)=>(
      text||text===0?text:'-'
    ),
    align:'right',
    ellipsis:true,
    width: 64,
    className:"table_companyCRDesc"


  },
  {
    title: '债项评级',
    dataIndex: 'bondLevel',
    key: 'bondLevel',
    render:(text:number)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 50,
    className:"table_bondCRDesc"
  },
  {
    title: '主体评级',
    dataIndex: 'companyLevel',
    key: 'companyLevel',
    // width: 100,
    render:(text:number)=>(
      text?text:'-'
    ),
    ellipsis:true,
    width: 50,
    className:"table_bondCRDesc"
  }
]
/**
 *
 * @param eventCode : 事件code;
 * @returns 返回匹配的对象
 */
export const getColumnsFromEventCode = (eventCode: string) => {
  switch (eventCode) {
    case "fund_manager_change":
      return columns_fund_manager_change;
      break;
    case "credit_alert":
      return columns_credit_alert;
      break;
    case "trade_condition_alert_status":
      return columns_three_table;
      break;
    case "trade_condition_alert_limit":
      return columns_three_table;
      break;
    case "dividend_alert":
      return columns_add_table;
      break;
    case "stock_consensus_alert":
      return columns_stock_consensus_alert;

      break;
    case "bond_deviate_valuation_negative_change":
      return columns_credit_price;
      break;
    case "bond_deviate_valuation_positive_change":
      return columns_credit_price;
      break;  
    default:
      return []
      break;
  }

}

export const PROVINCE_CODE_JSON = {
  '110000': '北京市',
  '120000': '天津市',
  '130000': '河北省',
  '140000': '山西省',
  '150000': '内蒙古自治区',
  '210000': '辽宁省',
  '220000': '吉林省',
  '230000': '黑龙江省',
  '310000': '上海市',
  '320000': '江苏省',
  '330000': '浙江省',
  '340000': '安徽省',
  '350000': '福建省',
  '360000': '江西省',
  '370000': '山东省',
  '410000': '河南省',
  '420000': '湖北省',
  '430000': '湖南省',
  '440000': '广东省',
  '450000': '广西壮族自治区',
  '460000': '海南省',
  '500000': '重庆市',
  '510000': '四川省',
  '520000': '贵州省',
  '530000': '云南省',
  '540000': '西藏自治区',
  '610000': '陕西省',
  '620000': '甘肃省',
  '630000': '青海省',
  '640000': '宁夏回族自治区',
  '650000': '新疆维吾尔自治区',
  '710000': '台湾省',
  '810000': '香港特别行政区',
  '820000': '澳门特别行政区',
}

// 债券类型
export const BOND_TYPE = [
  { value: '1', label: '利率债-政策性国债' },
  { value: '2', label: '其他利率债' },
  { value: '3', label: '可转债' },
  { value: '4', label: '金融机构信用债' },
  { value: '5', label: '资产证券化' },
  { value: '6', label: '非金融机构信用债' },
]